import 'package:flutter/material.dart';
import 'package:flutter_app_study/view/loadStateLayout.dart';

//四种视图状态例子
class DynamicFragment extends StatefulWidget {
  @override
  _DynamicFragmentState createState() => _DynamicFragmentState();
}

class _DynamicFragmentState extends State<DynamicFragment> {
  var loadState = LoadState.State_Loading;

  @override
  void initState() {
    // TODO: implement initState
    Future.delayed(Duration(seconds: 1), () {
      loadState = LoadState.State_Error;
      setState(() {});
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(loadState.toString()),
      ),
      body: LoadStateLayout(
        state: loadState,
        errorRetry: () {
          loadState = LoadState.State_Success;
          setState(() {
          });
        },
        successWidget: Container(
          child: Text("我是要显示的内容"),
        ),
      ),
    );
  }
}
